package hr.ctg.domain.model;

// Generated 2007.05.02 22:50:59 by Hibernate Tools 3.2.0.b9

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Immutable;
import org.hibernate.validator.NotNull;

/**
 * TipObjekta generated by hbm2java
 */
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Immutable
@Table(name = "tip_objekta")
@NamedQueries( {
		@NamedQuery(name = "TipObjekta.findAll", query = "select to from TipObjekta to"),
		@NamedQuery(name = "TipObjekta.findByObjekti", query = "select distinct to from TipObjekta to join to.objekts"),
		@NamedQuery(name = "TipObjekta.findByIdMjesta", query = "select distinct o.tipObjekta from Objekt o where o.mjesto.idMjesta = ?"),
		@NamedQuery(name = "TipObjekta.findByIdOtoka", query = "select distinct to from TipObjekta to join to.objekts o where o.mjesto.otok.idOtoka = ?"),
		@NamedQuery(name = "TipObjekta.findByIdZupanije", query = "select distinct to from TipObjekta to join to.objekts o where o.mjesto.zupanija.idZupanje = ?") })
public class TipObjekta implements java.io.Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -8482820520999203127L;
	private int idTipaObjekta;
	private String naziv;
	private Set<Objekt> objekts = new HashSet<Objekt>(0);
	private Set<Osobina> osobinas = new HashSet<Osobina>(0);

	public TipObjekta() {
	}

	public TipObjekta(final int idTipaObjekta) {
		this.idTipaObjekta = idTipaObjekta;
	}

	public TipObjekta(final int idTipaObjekta, final String naziv) {
		this.idTipaObjekta = idTipaObjekta;
		this.naziv = naziv;
	}

	public TipObjekta(final int idTipaObjekta, final String naziv,
			final Set<Objekt> objekts) {
		this.idTipaObjekta = idTipaObjekta;
		this.naziv = naziv;
		this.objekts = objekts;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id_tipa_objekta", unique = true, nullable = false)
	@NotNull
	public int getIdTipaObjekta() {
		return idTipaObjekta;
	}

	public void setIdTipaObjekta(final int idTipaObjekta) {
		this.idTipaObjekta = idTipaObjekta;
	}

	@Column(name = "naziv", nullable = false)
	@NotNull
	public String getNaziv() {
		return naziv;
	}

	public void setNaziv(final String naziv) {
		this.naziv = naziv;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "tipObjekta")
	public Set<Objekt> getObjekts() {
		return objekts;
	}

	public void setObjekts(final Set<Objekt> objekts) {
		this.objekts = objekts;
	}

	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		final TipObjekta other = (TipObjekta) obj;
		if (idTipaObjekta != other.getIdTipaObjekta()) {
			return false;
		}
		return true;
	}

	@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "tipObjektas")
	public Set<Osobina> getOsobinas() {
		return osobinas;
	}

	public void setOsobinas(final Set<Osobina> osobinas) {
		this.osobinas = osobinas;
	}

	@Override
	public String toString() {
		return Integer.toString(idTipaObjekta);
	}
}
